package com.zqxq.lottery.controller.jczq;

import com.zqxq.common.constant.Result;
import com.zqxq.common.enums.CodeEnum;
import com.zqxq.lottery.entity.bo.jczq.JczqWorldCupBO;
import com.zqxq.lottery.entity.vo.jczq.JczqWorldCupVO;
import com.zqxq.lottery.service.jczq.IJczqWorldCupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@Slf4j
public class JczqWorldCupController extends JczqBaseController {

    @Autowired
    private IJczqWorldCupService jczqWorldCupService;

    @PostMapping("/world/cup/list")
    public Result queryWorldCupList(@RequestBody JczqWorldCupBO search){
        Result rs = new Result();
        try{
            List<JczqWorldCupVO> list =  jczqWorldCupService.queryWorldCupList(search);
            rs.setData(list);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("QueryWorldCupList Error:",e);
        }
        return rs;
    }

    @PostMapping("/world/queryAgainstPlanUrl")
    public Result queryAgainstPlanUrl(){
        Result rs = new Result();
        try{
            String url = jczqWorldCupService.queryAgainstPlanUrl();
            rs.setData(url);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
        }
        return rs;
    }

    @PostMapping("/world/cup/map")
    public Result<Map<String,JczqWorldCupVO>> queryWorldCupMap(@RequestBody JczqWorldCupBO search){
        Result rs = new Result();
        try{
            Map<String,JczqWorldCupVO> map = new HashMap();
            List<JczqWorldCupVO> list =  jczqWorldCupService.queryWorldCupList(search);
            for(JczqWorldCupVO vo:list){
                map.put(vo.getPeriod()+"_"+vo.getType()+"_"+vo.getCode(),vo);
            }
            rs.setData(map);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("QueryWorldCupList Error:",e);
        }
        return rs;
    }

}
